<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="lib/react.development.js"></script>
    <script src="lib/react-dom.development.js"></script>
    <script src="lib/babel.min.js"></script>
    <script src="lib/prop-types.js"></script>

</head>
<body>
    <div id="root"></div>

    <script type="text/babel">
        const root =  ReactDOM.createRoot(document.getElementById("root"));

        class App extends React.Component {
            render() {
                return (
                    <Child userName={"魏虎华"} age={25}></Child>
                )
            }
        }
        class Child extends React.Component {
             // 定义一个名字为propTypes的静态属性,值的类型是一个对象
            // userName是组件要限制的属性名
            // PropTypes来自于prop-types.js文件
            // 限制userName属性值的类型是一个字符串
            // 限制age属性值的类型是一个数字且不允许为undefined
            // array func object
            static propTypes = {
                userName: PropTypes.string,
                age: PropTypes.number
            }
            static defaultProps = {
                sex:'女' // 增加默认值
            }
            render(){
                return (
                    <div>
                        <p>姓名:{this.props.userName}</p>
                        <p>年龄:{this.props.age}</p>
                        <p>性别:{this.props.sex}</p>
                    </div>
                )
            }
        }
        root.render((
            <App></App>
        ))
    </script>
</body>
</html>